<script>
	export default {
		onLaunch: function() {
			this.play()
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
			if (this.globalData.bgMusic.status !== 'play' && this.globalData.bgMusic.stage === 'back') {
				this.globalData.bgMusic.status = 'play'
				this.globalData.bgMusic.stage = 'font'
				this.globalData.bgMusic.play()
			}
		},
		onHide: function() {
			if (this.globalData.bgMusic.status === 'play') {
				this.globalData.bgMusic.status = 'pause'
				this.globalData.bgMusic.stage = 'back'
				this.globalData.bgMusic.pause()
			}
			console.log('App Hide')
		},
		globalData: {
			user_id: "",
			bgMusic: "",
			award: ""
		},
		methods: {
			play() {
				this.globalData.bgMusic = uni.createInnerAudioContext()
				this.globalData.bgMusic.src = 'https://hykoc.oss-cn-beijing.aliyuncs.com/statics/gy/music.mp3'
				this.globalData.bgMusic.obeyMuteSwitch = false
				this.globalData.bgMusic.autoplay = true
				this.globalData.bgMusic.loop = true
				this.globalData.bgMusic.status = 'play'
				this.globalData.bgMusic.onPlay(() => {
					console.log('背景音频播放事件');
					this.globalData.bgMusic.status = 'play'
				});
				this.globalData.bgMusic.onPause(() => {
					console.log('背景音频暂停事件');
					this.globalData.bgMusic.status = 'pause'
				});
				this.globalData.bgMusic.onStop(() => {
					console.log('背景音频停止事件');
					this.globalData.bgMusic.status = 'stop'
				});
				this.globalData.bgMusic.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});
			},
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import '@/static/css/animate.css';

	.p-absolute {
		position: absolute;
	}

	.container {
		width: 100%;
		height: 100vh;
		overflow: hidden;
	}
</style>